<html>
    <head>
        <style type="text/css">@import url({$FORM_ACTION}/library/dynarch_calendar.css);</style>
        <script type="text/javascript" src="{$FORM_ACTION}/library/dialog.js"></script>
        <script type="text/javascript" src="{$FORM_ACTION}/library/textformat.js"></script>
        <script type="text/javascript" src="{$FORM_ACTION}/library/dynarch_calendar.js"></script>
        {php} include_once("{$GLOBALS['srcdir']}/dynarch_calendar_en.inc.php"); {/php}
        <script type="text/javascript" src="{$FORM_ACTION}/library/dynarch_calendar_setup.js"></script>

        <script type="text/javascript">
            var mypcc = '{php} echo $GLOBALS['phone_country_code'] {/php}';
            {
                literal
            }
            // Only load jquery if not already closing. This page serves two purposes now,
            //  for entring of vitals and for graphing/trending previous vitals by being embedded
            //  in the interface/patient_file/encounter/trend_form.php page.
            if (typeof jQuery == 'undefined') {
                document.write("<script type='text/javascript' src='{/literal}{php}echo $GLOBALS['webroot'];{/php}{literal}/library/js/jquery.js'><\/script>")
            }
        </script>
        <style type="text/css" title="mystyles" media="all">
            .title {
                font-size: 120%;
                font-weight: bold;
            }
            .currentvalues {
                border-right: 0px solid black;
                padding-right:5px;
                text-align: left;
            }
            .valuesunfocus {
                border-right: 0px solid black;
                padding-right:5px;
                background-color: #ccc;
                text-align: left;
            }
            .unfocus {
                background-color: #ccc;
            }
            .historicalvalues {
                background-color: #ffffff;
                border: 1px solid #ddd;
                text-align: right;
                width: 50px;
            }
            table {
                border-collapse: collapse;
                font-size: 10px;
            }
            td,th {
                padding-right: 15px;
                padding-left: 15px;
            }
            .hide {
                display:none;
            }
            .readonly {
                display:none;
            }
            .btnSAC {
                background-color: #31B6AC;
                border: medium none;
                border-radius: 0 0 0 0;
                color: #FFFFFF;
                cursor: pointer;
                margin-left: 20px;
                padding: 5px;
            }
        </style>
        {/literal}

    </head>
    <body>
        <div class="borde_normal">
            <div class="borde_normal">
                <span class="historial_paciente"><i style="font-size: 1.4em;" class="icon-bar-chart"></i> Signos Vitales</span>
           </div>

            <div id="chart"></div>

            <form name="vitals" method="post" action="{$FORM_ACTION}/interface/forms/vitals/save.php" onSubmit="return top.restoreSession()">


                <div class="tabla_vitals">
                    <table>
                        <tr>
                            <th colspan="2" align="left" class='patient_info_left'><span>Signos vitales</span></th>
                        </tr>
                        <tr>
                            <th align="left" style="padding-left: 15px;padding-right: 130px;text-align: left">{xl t="Name"}</th>
                            <th align="left" style="padding-left: 15px;padding-right: 30px;text-align: left">{xl t="Unit"}</th>
                            <th class='currentvalues' title='{xl t='Date and time of this observation'}'>
                                <input type='text' size='14' name='date' id='date'
                                   value='{$vitals->get_date()|date_format:"%Y-%m-%d %H:%M"}'
                                   onkeyup='datekeyup(this, mypcc, true)' onblur='dateblur(this, mypcc, true)' />
                                <img src='{$FORM_ACTION}/interface/pic/show_calendar.gif' id='img_date' align='absbottom'
                                     width='24' height='22' border='0' alt='[?]' style='cursor:pointer' />
                            </th>
                            {foreach item=result from=$results}
                            <th class='historicalvalues'>{$result.date|date_format:"%d/%m/%Y"}</th>
                            {/foreach}</tr>

                        {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 2}<td class="unfocus graph" id="weight">{else}<td class="graph" id="weight">{/if}{xl t="Weight"}</td>
                            {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="lbs"}</td>
                            {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' name='weight' id='weight_input' value="{if $vitals->get_weight() != 0}{$vitals->get_weight()}{/if}" onChange="convLbtoKg('weight_input');"/>
                            </td>		
                            {foreach item=result from=$results}
                            <td  class='historicalvalues'>{if $result.weight != 0}{$result.weight}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 1}<td class="unfocus graph" id="weight_metric">{else}<td class="graph" id="weight_metric">{/if}{xl t="Weight"}</td>
                            {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="kg"}</td>
                            {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' id='weight_input_metric' value="{if $vitals->get_weight() != 0}{math equation="number * constant" number=$vitals->get_weight() constant=0.45359237 format="%.2f"}{/if}" onChange="convKgtoLb('weight_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td  class='historicalvalues'>{if $result.weight != 0}{math equation="number * constant" number=$result.weight constant=0.45359237 format="%.2f"}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 2}<td class="unfocus graph" id="height">{else}<td class="graph" id="height">{/if}{xl t="Height"}</td>
                            {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="in"}</td>
                            {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' name='height' id='height_input' value="{if $vitals->get_height() != 0}{$vitals->get_height()}{/if}" onChange="convIntoCm('height_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.height != 0}{$result.height}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 1}<td class="unfocus graph" id="height_metric">{else}<td class="graph" id="height_metric">{/if}{xl t="Height"}</td>
                            {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="cm"}</td>
                            {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' id='height_input_metric' value="{if $vitals->get_height() != 0}{math equation="number * constant" number=$vitals->get_height() constant=2.54 format="%.2f"}{/if}" onChange="convCmtoIn('height_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.height != 0}{math equation="number * constant" number=$result.height constant=2.54 format="%.2f"}{/if}</td>
                            {/foreach}</tr>

                        <tr><td class="graph" id="bps">{xl t="BP Systolic"}</td><td>{xl t="mmHg"}</td>
                            <td class='currentvalues'><input type="text" size='5'
                                                             name='bps' id='bps_input' value="{$vitals->get_bps()}"/></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.bps}</td>
                            {/foreach}</tr>
                        <tr><td class="graph" id="bpd">{xl t="BP Diastolic"}</td><td>{xl t="mmHg"}</td>
                            <td class='currentvalues'><input type="text" size='5'
                                                             name='bpd' id='bpd_input' value="{$vitals->get_bpd()}"/></td>
                            {foreach item=result from=$results}
                            <td  class='historicalvalues'>{$result.bpd}</td>
                            {/foreach}</tr>
                        <tr><td class="graph" id="pulse">{xl t="Pulse"}</td><td>{xl t="per min"}</td>
                            <td class='currentvalues'><input type="text" size='5'
                                                             name='pulse' id='pulse_input' value="{if $vitals->get_pulse() != 0}{$vitals->get_pulse()|string_format:"%.0f"}{/if}"/></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.pulse != 0}{$result.pulse|string_format:"%.0f"}{/if}</td>
                            {/foreach}</tr>
                        <tr><td class="graph" id="respiration">{xl t="Respiration"}</td><td>{xl t="per min"}</td>
                            <td class='currentvalues'><input type="text" size='5'
                                                             name='respiration' id='respiration_input' value="{if $vitals->get_respiration() != 0}{$vitals->get_respiration()|string_format:"%.0f"}{/if}"/></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.respiration != 0}{$result.respiration|string_format:"%.0f"}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 2}<td class="unfocus graph" id="temperature">{else}<td class="graph" id="temperature">{/if}{xl t="Temperature"}</td>
                            {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="F"}</td>
                            {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' name='temperature' id='temperature_input' value="{if $vitals->get_temperature() != 0}{$vitals->get_temperature()}{/if}" onChange="convFtoC('temperature_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.temperature != 0}{$result.temperature}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 1}<td class="unfocus graph" id="temperature_metric">{else}<td class="graph" id="temperature_metric">{/if}{xl t="Temperature"}</td>
                            {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="C"}</td>
                            {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' id='temperature_input_metric' value="{if $vitals->get_temperature() != 0}{math equation="(number - constant2 ) * constant" number=$vitals->get_temperature() constant=0.5556 constant2=32 format="%.2f"}{/if}" onChange="convCtoF('temperature_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.temperature != 0}{math equation="(number - constant2 ) * constant" number=$result.temperature constant=0.5556 constant2=32 format="%.2f"}{/if}</td>
                            {/foreach}</tr>

                        <tr><td>{xl t="Temp Location"}<td></td></td>
                            <td class='currentvalues'><select name="temp_method" id='temp_method'/><option value=""> </option>  
                        <option value="Oral"              {if $vitals->get_temp_method() == "Oral"              || $vitals->get_temp_method() == 2 } selected{/if}>{xl t="Oral"}
                        <option value="Tympanic Membrane" {if $vitals->get_temp_method() == "Tympanic Membrane" || $vitals->get_temp_method() == 1 } selected{/if}>{xl t="Tympanic Membrane"}
                        <option value="Rectal"            {if $vitals->get_temp_method() == "Rectal"            || $vitals->get_temp_method() == 3 } selected{/if}>{xl t="Rectal"}
                        <option value="Axillary"          {if $vitals->get_temp_method() == "Axillary"          || $vitals->get_temp_method() == 4 } selected{/if}>{xl t="Axillary"}
                        <option value="Temporal Artery"   {if $vitals->get_temp_method() == "Temporal Artery" } selected{/if}>{xl t="Temporal Artery"}
                            </select></td>
                            {foreach item=result from=$results}
                        <td class='historicalvalues'>{if $result.temp_method}{xl t=$result.temp_method}{/if}</td>
                        {/foreach}</tr>

                        <tr><td class="graph" id="oxygen_saturation">{xl t="Oxygen Saturation"}</td><td>{xl t="%"}</td>
                            <td class='currentvalues'><input type="text" size='5'
                                                             name='oxygen_saturation' id='oxygen_saturation_input' value="{if $vitals->get_oxygen_saturation() != 0}{$vitals->get_oxygen_saturation()|string_format:"%.0f"}{/if}"/></td>
                            {foreach item=result from=$results}
                            <td  class='historicalvalues'>{if $result.oxygen_saturation != 0}{$result.oxygen_saturation|string_format:"%.0f"}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 2}<td class="unfocus graph" id="head_circ">{else}<td class="graph" id="head_circ">{/if}{xl t="Head Circumference"}</td>
                            {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="in"}</td>
                            {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' name='head_circ' id='head_circ_input' value="{if $vitals->get_head_circ() != 0}{$vitals->get_head_circ()}{/if}" onChange="convIntoCm('head_circ_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.head_circ != 0}{$result.head_circ}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 1}<td class="unfocus graph" id="head_circ_metric">{else}<td class="graph" id="head_circ_metric">{/if}{xl t="Head Circumference"}</td>
                            {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="cm"}</td>
                            {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' id='head_circ_input_metric' value="{if $vitals->get_head_circ() != 0}{math equation="number * constant" number=$vitals->get_head_circ() constant=2.54 format="%.2f"}{/if}" onChange="convCmtoIn('head_circ_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.head_circ != 0}{math equation="number * constant" number=$result.head_circ constant=2.54 format="%.2f"}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 4}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 2}<td class="unfocus graph" id="waist_circ">{else}<td class="graph" id="waist_circ">{/if}{xl t="Waist Circumference"}</td>
                            {if $units_of_measurement == 2}<td class="unfocus">{else}<td>{/if}{xl t="in"}</td>
                            {if $units_of_measurement == 2}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' name='waist_circ' id='waist_circ_input' value="{if $vitals->get_waist_circ() != 0}{$vitals->get_waist_circ()}{/if}" onChange="convIntoCm('waist_circ_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.waist_circ != 0}{$result.waist_circ}{/if}</td>
                            {/foreach}</tr>

                        {if $units_of_measurement == 3}<tr class="hide">{else}<tr>{/if}
                            {if $units_of_measurement == 1}<td class="unfocus graph" id="waist_circ_metric">{else}<td class="graph" id="waist_circ_metric">{/if}{xl t="Waist Circumference"}</td>
                            {if $units_of_measurement == 1}<td class="unfocus">{else}<td>{/if}{xl t="cm"}</td>
                            {if $units_of_measurement == 1}<td class="valuesunfocus">{else}<td class='currentvalues'>{/if}
                                <input type="text" size='5' id='waist_circ_input_metric' value="{if $vitals->get_waist_circ() != 0}{math equation="number * constant" number=$vitals->get_waist_circ() constant=2.54 format="%.2f"}{/if}" onChange="convCmtoIn('waist_circ_input');"/>
                            </td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.waist_circ != 0}{math equation="number * constant" number=$result.waist_circ constant=2.54 format="%.2f"}{/if}</td>
                            {/foreach}</tr>

                        <tr><td class="graph" id="BMI">{xl t="BMI"}</td><td>{xl t="kg/m^2"}</td>
                            <td class='currentvalues'><input type="text" size='5'
                                                             name='BMI' id='BMI_input' value="{if $vitals->get_BMI() != 0}{$vitals->get_BMI()|substr:0:5}{/if}"/></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{if $result.BMI != 0}{$result.BMI|substr:0:5}{/if}</td>
                            {/foreach}</tr>

                        <tr><td>{xl t="BMI Status"}</td><td>{xl t="Type"}</td>
                            <td class='currentvalues'><input type="text" size='15'
                                                             name="BMI_status" id="BMI_status' value="{$vitals->get_BMI_status()}"/></td>
                            {foreach item=result from=$results}
                            <td  class='historicalvalues'>{if $result.BMI_status}{xl t=$result.BMI_status}{/if}</td>
                            {/foreach}
                        </tr>
                    </table>
                    <table style="margin-top: 10px">
                        <tr>
                            <th colspan="2" align="left" class='patient_info_left'><span>Composici&oacute;n corporal</span></th>
                        </tr>
                        <tr><th align="left" style="padding-left: 15px;padding-right: 130px;text-align: left">{xl t="Name"}</th>
                            <th align="left" style="padding-left: 15px;padding-right: 30px;text-align: left">{xl t="Unit"}</th>
                            <th class='currentvalues' title='{xl t='Date and time of this observation'}'>
                                <input type='text' size='14' name='date' id='date'
                                   value='{$vitals->get_date()|date_format:"%Y-%m-%d %H:%M"}'
                                   onkeyup='datekeyup(this, mypcc, true)' onblur='dateblur(this, mypcc, true)' />
                                <img src='{$FORM_ACTION}/interface/pic/show_calendar.gif' id='img_date' align='absbottom'
                                     width='24' height='22' border='0' alt='[?]' style='cursor:pointer' />
                            </th>
                            {foreach item=result from=$results}
                            <th class='historicalvalues'>{$result.date|date_format:"%d/%m/%Y"}</th>
                            {/foreach}</tr>
                        <tr>
                            <td>Porcentaje de grasa corporal</td>
                            <td>%</td>
                            <td class='currentvalues'><input type="text" size='5' name="bodyfatpercent" id='bodyfatpercent' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.bodyfatpercent}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Nivel de grasa corporal</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="bodyfatrange" id='bodyfatrange' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.bodyfatrange}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Porcentaje de agua en el cuerpo</td>
                            <td>%</td>
                            <td class='currentvalues'><input type="text" size='5' name="bodywaterpercent" id='bodywaterpercent' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.bodywaterpercent}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Masa de agua en el cuerpo</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="bodywatermass" id='bodywatermass' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.bodywatermass}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Nivel de grasa viceral</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="visceralfatrating" id='visceralfatrating' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.visceralfatrating}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Consumo cal&oacute;rico diario</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="dailycalorieintake" id='dailycalorieintake' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.dailycalorieintake}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Edad metab&oacute;lica</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="metabolicage" id='metabolicage' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.metabolicage}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Masa muscular</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="musclemass" id='musclemass' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.musclemass}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Condici&oacute;n f&iacute;sica</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="physiquerating" id=physiquerating' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.physiquerating}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Masa &oacute;sea</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="bonemass" id='bonemass' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.bonemass}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Masa grasa</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="fatmass" id='fatmass' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.fatmass}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Masa libre de grasa</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="fatfreemass" id='fatfreemass' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.fatfreemass}</td>
                            {/foreach}
                        </tr>

                        <tr>
                            <td>Tasa metabolica basal</td>
                            <td></td>
                            <td class='currentvalues'><input type="text" size='5' name="basalmetabolicrate" id='basalmetabolicrate' value="" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.basalmetabolicrate}</td>
                            {/foreach}
                        </tr>

                        <tr><td>{xl t="Other Notes"}<td></td></td>
                            <td class='currentvalues'><input type="text" size='20'
                                                             name="note" id='note' value="{$vitals->get_note()}" /></td>
                            {foreach item=result from=$results}
                            <td class='historicalvalues'>{$result.note}</td>
                            {/foreach}</tr>
                    </table>
                </div>
                <div style="margin-top: 10px; text-align: center;">
                    {if $patient_age <= 20 || (preg_match('/month/', $patient_age))}
                    <!-- only show growth-chart button for patients < 20 years old -->
                    <!-- <input type="button" id="growthchart" value="{xl t="Growth-Chart"}" style='margin-left: 20px;'> -->
                    <input type="button" id="pdfchart" class="boton_normal" value="({xl t="PDF"})" style='margin-left: 20px;'>
                           <input type="button" id="htmlchart" class="boton_normal" value="({xl t="HTML"})" style='margin-left: 20px;'>
                           {/if}
                </div>
        </div>
        <input type="hidden" name="id" id='id' value="{$vitals->get_id()}" />
        <input type="hidden" name="activity" id='activity' value="{$vitals->get_activity()}">
        <input type="hidden" name="pid" id='pid' value="{$vitals->get_pid()}">
        <input type="hidden" name="process" id='process' value="true">
    </form>
</body>

<script language="javascript">
            var formdate = '{$vitals->get_date()|date_format:"%Y%m%d"}';
            // vitals array elements are in the format:
            //   date-height-weight-head_circumference
            var vitals = new Array();
            // get values from the current form elements
            vitals[0] = formdate + '-{$vitals->get_height()}-{$vitals->get_weight()}-{$vitals->get_head_circ()}';
            // historic values
            {foreach item = result from = $results}
            vitals[vitals.length] = '{$result.date|date_format:"%Y%m%d"}-{$result.height}-{$result.weight}-{$result.head_circ}';
            {/foreach}
                    var webroot = '{$FORM_ACTION}';
            var pid = '{$vitals->get_pid()}';
            var cancellink = '{$DONT_SAVE_LINK}';
            {
                literal
            }

            $(document).ready(function() {
                $("#growthchart").click(function() {
                    ShowGrowthchart();
                });
                $("#pdfchart").click(function() {
                    ShowGrowthchart(1);
                });
                $("#htmlchart").click(function() {
                    ShowGrowthchart(2);
                });
                $("#cancel").click(function() {
                    //location.href = cancellink;
                });
            });

            function ShowGrowthchart(doPDF) {
                // get values from the current form elements
                {/literal}
                        vitals[0] = formdate + '-' + $("#height_input").val() + '-' + $("#weight_input").val() + '-' + $("#head_circ_input").val();
                {
                    literal
                }
                // build the data string
                var datastring = "";
                for (var i = 0; i < vitals.length; i++) {
                    datastring += vitals[i] + "~";
                }
                newURL = webroot + '/interface/forms/vitals/growthchart/chart.php?pid=' + pid + '&data=' + datastring;
                if (doPDF == 1)
                    newURL += "&pdf=1";
                if (doPDF == 2)
                    newURL += "&html=1";
                // do the new window stuff
                //top.restoreSession();
                window.open(newURL, '_blank', "menubar=1,toolbar=1,scrollbars=1,resizable=1,width=600,height=450");
            }

            function convLbtoKg(name) {
                var lb = $("#" + name).val();

                if (lb == "0") {
                    $("#" + name + "_metric").val("0");
                }
                else if (lb == parseFloat(lb)) {
                    kg = lb * 0.45359237;
                    kg = kg.toFixed(2);
                    $("#" + name + "_metric").val(kg);
                }
                else {
                    $("#" + name + "_metric").val("");
                }

                if (name == "weight") {
                    calculateBMI();
                }
            }

            function convKgtoLb(name) {
                var kg = $("#" + name + "_metric").val();

                if (kg == "0") {
                    $("#" + name).val("0");
                }
                else if (kg == parseFloat(kg)) {
                    lb = kg / 0.45359237;
                    lb = lb.toFixed(2);
                    $("#" + name).val(lb);
                }
                else {
                    $("#" + name).val("");
                }

                if (name == "weight_input") {
                    calculateBMI();
                }
            }

            function convIntoCm(name) {
                var inch = $("#" + name).val();

                if (inch == "0") {
                    $("#" + name + "_metric").val("0");
                }
                else if (inch == parseFloat(inch)) {
                    cm = inch * 2.54;
                    cm = cm.toFixed(2);
                    $("#" + name + "_metric").val(cm);
                }
                else {
                    $("#" + name + "_metric").val("");
                }

                if (name == "height_input") {
                    calculateBMI();
                }
            }

            function convCmtoIn(name) {
                var cm = $("#" + name + "_metric").val();

                if (cm == "0") {
                    $("#" + name).val("0");
                }
                else if (cm == parseFloat(cm)) {
                    inch = cm / 2.54;
                    inch = inch.toFixed(2);
                    $("#" + name).val(inch);
                }
                else {
                    $("#" + name).val("");
                }

                if (name == "height_input") {
                    calculateBMI();
                }
            }

            function convFtoC(name) {
                var Fdeg = $("#" + name).val();
                if (Fdeg == "0") {
                    $("#" + name + "_metric").val("0");
                }
                else if (Fdeg == parseFloat(Fdeg)) {
                    Cdeg = (Fdeg - 32) * 0.5556;
                    Cdeg = Cdeg.toFixed(2);
                    $("#" + name + "_metric").val(Cdeg);
                }
                else {
                    $("#" + name + "_metric").val("");
                }
            }

            function convCtoF(name) {
                var Cdeg = $("#" + name + "_metric").val();
                if (Cdeg == "0") {
                    $("#" + name).val("0");
                }
                else if (Cdeg == parseFloat(Cdeg)) {
                    Fdeg = (Cdeg / 0.5556) + 32;
                    Fdeg = Fdeg.toFixed(2);
                    $("#" + name).val(Fdeg);
                }
                else {
                    $("#" + name).val("");
                }
            }

            function calculateBMI() {
                var bmi = 0;
                var height = $("#height_input").val();
                var weight = $("#weight_input").val();
                if (height == 0 || weight == 0) {
                    $("#BMI").val("");
                }
                else if ((height == parseFloat(height)) && (weight == parseFloat(weight))) {
                    bmi = weight / height / height * 703;
                    bmi = bmi.toFixed(1);
                    $("#BMI_input").val(bmi);
                }
                else {
                    $("#BMI_input").val("");
                }
            }

            Calendar.setup({inputField: "date", ifFormat: "%Y-%m-%d %H:%M", button: "img_date", showsTime: true});

</script>
{/literal}

</html>
